/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package general.util;


import jpa.entity.Permissions;
import jpa.entity.User;

/**
 *
 * @author isaias
 */
public class SharedPermission {

    public SharedPermission() {
    }


    public static boolean hasPermission(String permission, User user){



        if (user.getLogin().equalsIgnoreCase("admin") || user.isIsAdministrator()) {
            return true;
        }
         try{
            for (Permissions permissions : user.getPermissions()) {

                    if (permission.equals(permissions.getName())) {
                        return true;
                    }

            }
        }catch(Exception ex){
            ex.printStackTrace();
        }
        return false;
    }
}
